﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Effects;
using GreyscaleEffectApp;
using ScrumTable.BL.DM.DataManagement;
using ScrumTable.UI.ViewModel;
using Brush=System.Windows.Media.Brush;
using Color=System.Windows.Media.Color;

#endregion

namespace ScrumTable.UI.View.Converter
{

    /// <summary>
    /// converts a iteration date to a brush (gray if its in the past)
    /// </summary>
    [ValueConversion(typeof(object), typeof(Brush))]
    public class ConverterIterationBackGround : IValueConverter
    {

        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        public string BackgroundName { get; set; }
        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------
        public ConverterIterationBackGround()
        {
            BackgroundName = "ListBoxBackgroundGray";
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------
        /// <summary>
        /// object -> brush
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>
        /// converts a iteration date to a brush (gray if its in the past)
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is IterationViewModel)
            {
                var iteration = (IterationViewModel)value;
                if( iteration.EndTime >= DateTime.Now.Date && iteration.StartTime <= DateTime.Now.Date)
                {
                    //return new SolidColorBrush(Color.FromArgb(255, 0xDF, 0xE5, 0xEE));
                    return new SolidColorBrush(Color.FromArgb(255, 0xE5, 0xE5, 0xE5));
                }
            }
            return Application.Current.TryFindResource(BackgroundName);
        }

        /// <summary>
        /// Not supported. Throws NotSupportedException.
        /// </summary>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
        
       

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion


    }
}
